package handlers

import (
	"github.com/gin-gonic/gin"
	"pic-text-pub/moders"
)

var a moders.Article

func Add(c *gin.Context) {
	title := c.PostForm("title")
	content := c.PostForm("content")
	picture := c.PostForm("picture")
	a.Title = title
	a.Content = content
	a.Picture = picture
	if err := a.AddArticle(moders.DB); err != nil {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}
func List(c *gin.Context) {
	list, err := a.List(moders.DB)
	if err != nil {
		c.JSON(200, gin.H{
			"msg":  "展示失败",
			"code": 400,
		})
		return
	}
	c.JSON(200, gin.H{
		"msg":  "展示成功",
		"code": 200,
		"list": list,
	})
}
